package shangjun;


import java.util.*;

/**
 * Created by sahngjun on 2017-4-22.
 */
public class Day02 {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int array[][] = new int[n][2];
        for (int i = 0; i < array.length; i++) {
            array[i][0] = sc.nextInt();
            array[i][1] = sc.nextInt();
        }

        int length = FindMax(array);
        System.out.println(length);
    }

    public static int FindMax(int[][] array) {
        if (array == null || array.length == 0
                || array[0] == null || array[0].length != 2)
            return 0;
        Arrays.sort(array, new Comparator<int[]>() {
            public int compare(int[] array1, int[] array2) {
                if (array1[0] == array2[0])
                    return array2[1] - array1[1];
                else
                    return array1[0] - array2[0];
            }
        });
        int tmp[] = new int[array.length];
        int length = 0;
        for (int[] envelope : array) {
            int index = Arrays.binarySearch(tmp, 0, length, envelope[1]);
            if (index < 0)
                index = -index - 1;
            tmp[index] = envelope[1];
            if (index == length)
                length++;
        }
        return length;
    }

}
